Page({

  /**
   * 页面的初始数据
   */
  data: {
    school_list: [],
    school_index: 0,
    interest_list: [],
    selected: [],
    num: 0, 
    registerFlag:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var selected = []
    var i
    for (i = 0; i < 12; i++) {
      selected[i] = false
    }
    this.setData({
      school_list: getApp().globalData.school_list,
      interest_list: getApp().globalData.interest_list,
      selected: selected
    })
  },
  select: function(e) {
    console.log(e)
    var i, num = this.data.num
    var selected = this.data.selected
    if (!selected[e.target.id]) num++;
    else num--;
    console.log(num);
    if (num <= 5){
      selected[e.target.id] = !selected[e.target.id]
      this.setData({selected: selected,num:num})
      console.log(this.data.selected);
    }else{
      return;
    }
  },
  authorize:function(){
    var that=this
    this.setData({ registerFlag: !that.data.registerFlag})
  },
  register:function(){
    var i,j=0
    getApp().globalData.userInfo.school=this.data.school_list[this.data.school_index]
    for(i=0;i<12;i++){
      if(this.data.selected[i]){
        getApp().globalData.userInfo.interest[j]=this.data.interest_list[i]
        j++
      }
    }
    getApp().registerUser()
  }
})